using System.Linq;

namespace ZMap
{
    public readonly struct TileCoord
    {
        public readonly int Z;
        public readonly int X;
        public readonly int Y;

        public TileCoord(int z, int x, int y)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public static string GetKeyZxy(int z, int x, int y)
        {
            return $"{z}/{x}/{y}";
        }

        public string GetKey()
        {
            return GetKeyZxy(Z, X, Y);
        }

        public static TileCoord FromKey(string key)
        {
            var numbers = key.Split('/').Select(int.Parse).ToArray();
            return new TileCoord(numbers[0], numbers[1], numbers[2]);
        }

        public override int GetHashCode()
        {
            return X << Z + Y;
        }
    }
}